#include<stack>
#include<vector>
#include<string>
#include<cctype>
#include<iostream>
using std::string;
using std::vector;
using std::stack;
using std::isdigit;
using std::isalpha;
using std::stoi;


class Solution {
    int getNumber(string& s, size_t& ptr) {
        string digitStr;
        while (isdigit(s[ptr])) {
            digitStr.push_back(s[ptr++]);
        }
        return stoi(digitStr);
    }

    string getStr(vector<string>& strVec) {
        string tmp;
        int i = strVec.size() - 1;
        while (i >= 0 && strVec[i] != "[") {i--;}

        int j = i+1;
        for (; j < strVec.size(); j++) tmp += strVec[j];

        for (j = strVec.size()-1; j >= i; j--) {
            strVec.pop_back();
        }
        return tmp;

    }
    

public:
    string decodeString(string s) {
        vector<string> strVec;
        stack<int> repeatStack;
        size_t ptr = 0;
        string tmp;
        while (ptr < s.size()) {
            // std::cout << ptr << " " << repeatStack.size() << " " << strVec.size() << "\n";
            // for (auto s: strVec) std::cout << s << " ";
            // std::cout << "\n";
            if (isdigit(s[ptr])) repeatStack.push(getNumber(s, ptr));
            else if (isalpha(s[ptr]) || s[ptr] == '[') {
                tmp = s[ptr++];
                strVec.push_back(tmp);
            }
            else {
                // 遇到]，取出字符串并乘，故而遍历完后没有数字
                string concatS = getStr(strVec);
                tmp = "";
                auto repeat = repeatStack.top();
                repeatStack.pop();
                for (int i = 0; i < repeat; i++) {
                    tmp += concatS;
                }
                strVec.push_back(tmp);
                ptr++;
            }
        }
        string ans;
        for (auto i = 0; i < strVec.size(); i++) {
            ans += strVec[i];
        }
        return ans;

    }
};


int main() {
    string input;
    std::cin >> input;
    std::cout << input << "\n";
    string ans = Solution().decodeString(input);
    std::cout << ans << "\n";
    return 0;
}